<template>
  <div class="list-page-chadc">
    <pub-search
      no-searchColumns="true"
      mask-append-to="table-container"
      @search="search"
    >
      <template #leftBtn>
        <el-button :icon="Plus" type="primary" @click="add('')">新增</el-button>
      </template>
    </pub-search>
    <div class="table-container" style="height: calc(100% - 90px)">
      <pub-table ref="pubTable" :column="table.columns" :data="table.data">
        <template v-slot:option="scope">
          <el-button
            el-button
            class="btn-row-add"
            plain
            type="success"
            @click="add(scope.row.id)"
          >
            编辑
          </el-button>
          <!-- <el-button
            el-button
            class="btn-row-add"
            plain
            type="danger"
            @click="del(scope.row.id)"
          >
            删除
          </el-button> -->
        </template>
      </pub-table>
    </div>
    <pub-dialog
      :title="dialogTitle"
      v-model="pageData.formVisiable"
      width="1000px"
    >
      <edit-form
        v-if="pageData.editId"
        :edit-id="pageData.editId"
        @success="getPageData"
        @cancel="pageData.formVisiable = false"
      ></edit-form>
      <add-form
        v-else
        @success="getPageData"
        @cancel="pageData.formVisiable = false"
      ></add-form>
    </pub-dialog>
    <pub-pagination
      :total="total"
      v-model:page="searchForm.pageNum"
      v-model:limit="searchForm.pageSize"
      @pagination="getPageData"
    />
  </div>
</template>
<script setup>
import { computed, onMounted, reactive, ref } from 'vue'
import { Delete, Edit, Search, Plus } from '@element-plus/icons-vue'
import { useUserStore } from '@/pinia/modules/user'
import { get_list } from '@/api/ZJGL/lqsqwh'
import { ElMessage, ElMessageBox } from 'element-plus'
import editForm from './components/edit.vue'
import addForm from './components/add.vue'
const orgInfo = useUserStore().orgInfo
const searchForm = ref({
  pageSize: 15,
  pageNum: 1
})
const emit = defineEmits(['changeCom'])
const total = ref(0)
const table = reactive({
  columns: [
    { label: '市', prop: 'cityName' },
    { label: '县', prop: 'countyName' },
    {
      label: '是否财政直管',
      prop: 'isVasaRecta',
      type: 'formatDict',
      formatCode: 'SF'
    },
    {
      label: '是否老去苏区',
      prop: 'keyAreaCode',
      type: 'formatDict',
      formatCode: 'ZDLQSQ'
    },
    { label: '操作', type: 'option', width: '80' }
  ],
  data: []
})
const pageData = reactive({
  formVisiable: false,
  detailVisiable: false,
  editId: ''
})
const getPageData = async () => {
  let res = await await get_list(searchForm.value)
  table.data = res.data
  total.value = res.total
}
const add = id => {
  pageData.editId = id
  pageData.formVisiable = true
}
const dialogTitle = computed(() => {
  return pageData.editId ? '编辑' : '新增'
})
const del = id => {
  ElMessageBox.confirm('确认要删除选择的记录吗?', '提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      //   warehouses_del(id).then(res => {
      //     if (res.succeed) {
      //       getPageData()
      //     }
      //   })
    })
    .catch(() => {})
}
const search = () => {
  searchForm.value.pageNum = 1
  getPageData()
}
onMounted(() => {
  getPageData()
})
</script>
<style lang="scss" scoped>
@import '@/style/chadche.scss';
</style>
